<?php 

class Event_ProfileForm extends Crud_Event_Handler 
{
	protected $_type = 'form';
		
	public function run($form)
	{
		$element = $form->getElement('password');
		$password = $this->_getParam('password');
		
		if (!$form->getRow()) {
			if ($password) {
				$filter = new Filter_Password();
				$encryptedPassword = $filter->filter($password);
				$this->_setParam('password', $encryptedPassword);
			}
		} else {

			if ($password && ($password != $form->getRow()->getPassword())) {
				$filter = new Filter_Password();
				$encryptedPassword = $filter->filter($password);
				$this->_setParam('password', $encryptedPassword);
			} else {
				$this->_setParam('password', $form->getRow()->getPassword());
			}
		}

	}
}

